<h2>php+mysql简易微信端口罩预约系统</h2>
推荐使用集成环境php(5.4-5.6) + mysql(5.6)。<br>
<?php
include "./inc/conn.php";
include "./inc/safe.php";
include "./inc/pubs.php";
include "./inc/sqls.php";
header("content-Type: text/html; charset=utf-8");//输出编码
Function mu($ef,$ue){
global $no,$te,$dr,$ur,$tk,$lr,$rf,$tv,$ow;
$db=ConnectMysqli::getIntance($conn);
$sql="describe `{$no}`";
$pass=$db->query($sql);
if(!$pass){
$sq="CREATE TABLE `{$no}` (
`id` int(10) unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,
`{$rf}` varchar(32) DEFAULT '-',
`{$ow}` varchar(32) DEFAULT '-',
`{$tv}` varchar(32) DEFAULT '-',
`{$lr}` varchar(32) DEFAULT '-',
`{$te}` varchar(32) DEFAULT '-',
`{$ur}` varchar(32) DEFAULT '-',
`{$tk}` varchar(32) DEFAULT '-',
`isyue` int(2) DEFAULT '0',
`{$dr}` datetime DEFAULT CURRENT_TIMESTAMP,
`领取时间` datetime DEFAULT CURRENT_TIMESTAMP,
KEY `{$ow}` (`{$ow}`),
KEY `{$lr}` (`{$lr}`),
KEY `{$ur}` (`{$ur}`)
) ENGINE={$ef} DEFAULT CHARSET=utf8";
$pass=$db->query($sq);
if($pass){
return "创建{$no}成功";
}else{
return "创建{$no}失败({$sq})";
}
}else{
return "忽略创建：{$no}已存在;";
}
}
Function ti($ef,$ue){
global $no;
$db=ConnectMysqli::getIntance($conn);
$sql="describe `{$no}_shop`";
$pass=$db->query($sql);
if(!$pass){
$ar = rand(1, 9); $ndata=date("Y-m-d"); $yu=date("YmdHis");
$cdata = date("Y-m-d",strtotime("+3 day")) ;
$sq="CREATE TABLE `{$no}_shop` (
`id` int(10) unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,
`店铺名称` varchar(32) DEFAULT '某某连锁药店{$ar}店',
`店铺地址` varchar(32) DEFAULT '柳城镇王府井大街{$ar}号',
`联系电话` varchar(32) DEFAULT '1508888888{$ar}',
`营业时间` varchar(32) DEFAULT '9:00 - 15:00',
`预约批次` varchar(32) DEFAULT '{$yu}',
`可约份数` int(8) DEFAULT '88',
`每份数量` varchar(32) DEFAULT 'N95口罩2个',
`每份付费` varchar(32) DEFAULT '现场付11元',
`领取日期` varchar(32) DEFAULT '{$cdata}',
`check` int(2) DEFAULT '0',
KEY `店铺名称` (`店铺名称`)
) ENGINE={$ef} DEFAULT CHARSET=utf8";
$pass=$db->query($sq);
if($pass){
return "创建{$no}_shop成功";
}else{
return "创建{$no}_shop失败({$sq})";
}
}else{
return "已忽略：{$no}_shop已存在;";
}
}
//文件导入店铺数据
Function ya($di,$ue){
global $no,$tv,$rf,$at;
$ii=0;$ry="";$rz="";
//$od = date('YmdHis');
$db=ConnectMysqli::getIntance($conn);
$od = date("YmdHis",filemtime($di));
$ag="SELECT COUNT(*) FROM `{$no}` ";
$ag.=" WHERE `{$rf}` = '{$od}'";
$wh=$db->getRow($ag);
$cl=$wh['COUNT(*)'];
if($cl>0){
return "未执行写入：{$od}之前已执行(通过识别文件最后编辑时间的)!";
}
$handle = fopen($di,'r');
if ($handle) {
while (!feof($handle)) {
$ii++;
$out = fgets($handle, 4096);
$rl = explode("\t",$out);
$rn = count($rl);
if($ii>1 && $rn==8){
$ry = "'{$od}',";;
foreach($rl as $bj){
$bj = trim($bj);
$ry .= "'$bj',";
}
$rx = $od."|".$rl[0]."|".$rl[4];
da($rx,$ue);
$ry = trim($ry,',');
$rz .= "({$ry}),";
}
}
}
if($ii<2){
$ve = "<h3>导入异常!</h3>{$ii}";
}else{
$tim = "`预约批次`,`店铺名称`,`店铺地址`,`联系电话`,`营业时间`,`可约份数`,`每份数量`,`每份付费`,`领取日期`";
$rz = trim($rz,',');
$dosqls = "INSERT INTO `{$no}_shop` ({$tim}) VALUES {$rz}";
$echos=$db->query($dosqls);
if($echos){
$ve = "<h3>导入成功!</h3>进入批次{$od}查看导入结果";
}else{
$ve = "<h3>导入异常!</h3>{$dosqls}";
}
}
return "".$ve;
fclose($handle);
}
//导入1测试数据
Function da($ef,$ue){
global $no,$tv,$rf,$at;
$ra = explode("|",$ef);
$ue = $ra[2]; $an = $ra[1]; $av = $ra[0];
$fn = "";
for ($i = 0; $i < $ue; $i++) {
$fn .= "('{$av}','{$an}'),";
}
$fn = trim($fn,",");
$tim = "`批次号`,`网点信息`";
$db=ConnectMysqli::getIntance($conn);
$dosqls = "INSERT INTO `{$no}` ({$tim}) VALUES {$fn}";
$echos=$db->query($dosqls);
if($echos){
$ve = "导入成功!{$ue}笔";
}else{
$ve = "导入异常!{$dosqls}";
}
echo "<br>{$an}".$ve;
}
$iz = $_POST["fl"];
$ix = Trim($_POST["ca"]);
echo "<h2>{$iz}@{$ix}</h2>";
if(stristr("-InnoDB-MYISAM-",$iz)){
echo "<h2>创建{$no}表</h2>".mu("InnoDB",$userx);
echo "<h2>创建{$no}_shop表</h2>".ti("InnoDB",$userx);
$po = "./txt/{$ix}.txt";
if(file_exists($po)){
echo "<h2>导入数据演示</h2>".ya($po,$ue);
}else{
echo "<h2>提交的文件不存在</h2>英文名称哦：".$po;
}
}else{
?>
<h2>初始化设置</h2>
<h2>第一步</h2>
推荐notepad++等代码编辑器修改：<br>
手动修改inc/sqls.php对应数据库参数。<br>
手动修改inc/conn.php对应参数。<br>
<form name="qm" method="post" onsubmit="return sta(0);">
<h2>第二步</h2>本页根据实际情况选择数据库类型Innodb(或Myisam)。<br>
<select name="fl" id="fl" onBlur="sta(1)" >
<option value="InnoDB">InnoDB</option>
<option value="MYISAM">MYISAM</option>
</select>
<h2>第三步</h2>
导入数据样表Inc/demo.zip，xls转为txt后放txt文件夹下。<br>
刷新本页后更新选项，选择需要导入的数据提交。<br>
<select name="ca" id="ca" onBlur="sta(2)" >
<?php traverse(".txt");?>
</select>
<h2><input type="submit" name="button" class="buts" id="sub" value="立即提交" /></h2>
</form>
<?php
}
?>
<h2>还有第四步</h2>
<?php
//含端口转发
$cu = $_SERVER["SERVER_PORT"];
if($cu=="80" || $cu==""){
$se = "";
$wn = "http://".$me;
}elseif($cu=="443"){
$se = "";
$wn = "https://".$me;
}else{
$se = ":".$cu;
$wn = "http://".$me;
}
$request_dir = $_SERVER['PHP_SELF'];
$li = basename(__FILE__);
$request_dir = str_replace($li,"login.php",$request_dir);
$request_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';//参数
$tx = $wn.$se.$request_dir."?do={$ou}";
if(!file_exists($ld)){
echo "<h3>微信端扫码得管理员权限</h3><img src=\"inc/Qr.php?data={$tx}\" >";
}else{
echo "<h3管理员权限已分配</h3>如需更改请删除{$ld}后刷新本页后扫码。";
}
echo "<h2>如何追加批次</h2>更新或追加文件到txt文件夹下再次访问本页操作。<br>";
echo "文件样表见inc文件夹下的压缩包文件，xls文件是平时输入，上传的是.txt记事本文件。";
echo "<h2>如何重起炉灶(数据清空)</h2>修改inc/conn.php对应数据表名称<br>";
echo "然后访问本页导入数据，该方法是建立和以前不同的新表并导入数据。<br>";
echo "管理员权限也需变动则重复第四步（删文件{$ld}刷新本页后扫码）。";
?>
<h2>具备条件</h2>
需要管理员（使用者）具备FTP、域名绑定、网站空间使用、基本excel操作等技能。<br>
推荐有mysql管理软件经验，含数据备份、导入导出，表结构创建等。<br>
需要有认证公众号年付300那种(有微信登录权限并设置启用的域名白名单)。<br>